package yxy.game.pm2.bean.db.newDao;


import yxy.apple.db.DbManager;
import yxy.game.pm2.bean.db.po.YiLingBattlePo;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ljb
 * @date 2022/5/18 20:27
 **/
public class YiLingInfoDao {

    private static final String
            REPLACE_ONE = "replace into `yilingBattle` (`pCode`,`serverId`, `groupId`, `areaId`, `mapId`," +
            " `head`, `headFrame`, `username`, `level`, `power`, `updateTime`) values (?,?,?,?,?,?,?,?,?,?,?)",
            SELECT_ALL = "select * from `yilingBattle` where `groupId` = ? and `mapId` >= ? and `mapId` <= ?";

    public static List<YiLingBattlePo> getList(int groupId, int startMapId, int endMapId) {
        return DbManager.instance().executeQueryObjectList(SELECT_ALL, new Object[]{groupId, startMapId, endMapId}, YiLingBattlePo.builder);
    }

    public static boolean replace(List<YiLingBattlePo> yiLingBattlePos) {
        List<Object[]> list = new ArrayList<>();
        for (YiLingBattlePo po : yiLingBattlePos) {
            Object[] objects = new Object[]{po.getPlayerCode(),po.getServerId(), po.getGroupId(), po.getAreaId(), po.getMapId(), po.getHead(),
                    po.getHeadFrame(), po.getUsername(), po.getLevel(), po.getPower(), po.getUpdateTime()};
            list.add(objects);
        }
        int[] ints = DbManager.instance().executeBatchCommand(REPLACE_ONE, list);
        return ints.length == list.size();
    }

}
